let goods=require('../model/goods.js')
async function createGoods(good){
    let res=await goods.create(good)
    return res.dataValues
}

async function updateGoods(id,good){
    let res=await goods.update(good,{where:{id}})
    return res[0]>0?true:false
}

async function removeGoods(id){
   let res=await goods.destroy({where:{id}})
   return res>0?true:false
}

async function restoreGoods(id){
    let res=await goods.restore({where:{id}})
    console.log(res,'商品上架')
    return res>0?true:false
}

async function find(pageSize,pageNum){
    let offset=(pageNum-1)*pageSize
    let {count,rows}=await goods.findAndCountAll({
        offset,
        limit:pageSize*1
    })
    return  {
        total:count,
        goods:rows,
        pageSize,
        pageNum
    }
}
module.exports={
    createGoods,
    updateGoods,
    removeGoods,
    restoreGoods,
    find
}